package com.atguigu.gmall.item.controller;

import com.atguigu.gmall.common.cache.BloomName;
import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;

import com.atguigu.gmall.feign.product.SpuFeignClient;
import com.atguigu.gmall.item.service.ItemService;

import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author dyqstart
 * @create 2021-08-06-17:29
 * @since 1.0.0
 */
@RestController
@RequestMapping("/api/item")
public class SkuInfoController {

    @Autowired
    SpuFeignClient spuFeignClient;

    @Autowired
    ItemService itemService;


    @Qualifier(BloomName.SKU)//每一个bean的方法就是方法名
    @Autowired
    RBloomFilter<Object> skufilter;


    @GetMapping("/{skuId}")
    public Result getItem(@PathVariable Long skuId){


        Map<String,Object> skuInfo = itemService.getSkuInfo(skuId);

        //更新热度
        itemService.updateSkuHotScore(skuId);


        return Result.ok(skuInfo);

//        String cacheKey = RedisConst.SKUKEY_PREFIX+skuId+RedisConst.SKUKEY_SUFFIX;
//        //布隆说有不一定有，布隆说没有，就一定没有
//        if (skufilter.contains(cacheKey)){
//            //itemService   远程调用  service-product   获取到当前商品的所有详情
//
//
//        }
//        return null;

    }


////  测试远程调用
//    @GetMapping("/hello")
//    public Result<Page<SpuInfo>> getItem(){
//
//        Result<Page<SpuInfo>> pageResult = spuFeignClient.spuInfoPageList(61L, 1L, 10L);
//
//        return pageResult;
//
//    }
}
